<template>
    <div class="box">
        <div class="left">
            <h2 style="margin-left:15px;">Renter Car 后台管理</h2>
        </div>
        <div class="right">
            <span>欢迎您：{{admin}}</span>
            <span @click="logout">注销</span>
        </div>
    </div>
</template>

<script>
import Axios from "axios";
export default {
    data() {
        return {
            admin: ""
        };
    },
    created() {
        this.islogin();
    },
    methods: {
        islogin() {
            Axios.get("/admin/islogin").then(res => {
                if (res.data.isLogin) {
                    this.admin = res.data.admins; //修改页面显示名字
                } else {
                    this.$router.push("/login");
                }
            });
        },
        logout() {
            Axios.get("/admin/logout").then(res => {
                if (res.data) {
                    this.$router.push("/login");
                }
            });
        }
    }
};
</script>

<style scope>
.box {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
h2 {
    font-size: 17px;
    margin-left: 0px;
}
.right {
    /* margin-right: 300px; */
}

.right span {
    font-size: 14px;
    color: white;
    padding: 0px 20px;
    cursor: pointer;
}

.right :nth-child(2):hover {
    background: rgb(192, 67, 67);
}
</style>
